package com.fmblzf.library.text;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by Administrator on 2015/10/23.
 */
public class TextViewBorderColor extends TextView {

    //画线的画笔
    private Paint linePaint;
    //底边宽度
    private int strokeWidth = 8;
    //是否获得焦点
    private boolean isFouce = false;

    public TextViewBorderColor(Context context) {
        this(context, null, 0);
    }

    public TextViewBorderColor(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TextViewBorderColor(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        initWidget();

    }


    public void setIsFouce(boolean isFouce) {
        this.isFouce = isFouce;
        invalidate();
    }

    /**
     * 初始化界面属性
     */
    private void initWidget() {
        linePaint = new Paint();
        linePaint.setAntiAlias(true);
        linePaint.setColor(Color.parseColor("#fcf427"));
        linePaint.setStyle(Paint.Style.FILL);
        linePaint.setStrokeWidth(strokeWidth);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(isFouce) {
            canvas.drawLine(0, getHeight() - strokeWidth / 2, getWidth(), getHeight() - strokeWidth / 2, linePaint);
            canvas.restore();
        }
    }
}
